package vn.bus.bk.dialog;

import vn.bus.bk.R;
import vn.bus.bk.adapter.SQLiteAdapter;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.util.Log;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class DialogChooseCity {
    private Context mContext;

    public DialogChooseCity(Context context) {
	this.mContext = context;
    }

    public void show() {
	View view = View.inflate(mContext, R.layout.dialog_choose_city, null);
	AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
	final RadioGroup group = (RadioGroup) view
		.findViewById(R.id.radioGroup);

	RadioButton hn = (RadioButton) view.findViewById(R.id.radio0);
	RadioButton hcm = (RadioButton) view.findViewById(R.id.radio1);
	if (SQLiteAdapter.getNameCity(mContext) == 1) {
	    hn.setChecked(true);
	} else {
	    hcm.setChecked(true);
	}

	dialog.setTitle(mContext.getString(R.string.choose_city));
	dialog.setView(view);
	dialog.setNegativeButton(mContext.getString(R.string.cancel),
		new OnClickListener() {

		    @Override
		    public void onClick(DialogInterface dialog, int which) {
			// TODO Auto-generated method stub
			dialog.dismiss();
		    }
		});

	dialog.setPositiveButton(mContext.getString(R.string.yes),
		new OnClickListener() {

		    @Override
		    public void onClick(DialogInterface dialog, int which) {
			// TODO Auto-generated method stub
			switch (group.getCheckedRadioButtonId()) {
			case R.id.radio0:
			    SQLiteAdapter.setNameCity(1);
			    break;
			case R.id.radio1:
			    Log.i("option", "ho chi minh");
			    SQLiteAdapter.setNameCity(2);
			    break;
			default:
			    Log.i("option", "No one");
			    break;
			}

			Log.i("group", group.getChildAt(0).toString());
		    }
		});

	dialog.show();
    }
}
